<template>
  <div class="playList">
    <div class="title-img">
      <van-image style="border-radius: 50%" :src="img" fit="cover" />
      <van-icon name="arrow-left" @click="goBack" />
    </div>
    <div v-if="songUrl == ''" class="content-icon">
      <div class="box-left">
        <van-icon name="play-circle-o" class="icon" />
        <span>播放全部</span>
      </div>

      <div class="box-right">
        <span>收藏</span>
        <van-icon name="like-o" class="icon" />
      </div>
    </div>
    <div v-else>
      <audio :src="songUrl" autoplay controls></audio>
    </div>
    <div class="list">
      <ul class="content">
        <li
          v-for="item in playlistData"
          :key="item.songid"
          class="item"
          @click="selectSong(item)"
        >
          <div class="songname">{{ item.songname }}</div>
          <div class="singInfo">
            {{ item.albumname }} -- {{ item.singer[0].name }}
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      value: "",
      playlistData: [],
      img: "",
      songUrl: "",
    };
  },
  created() {
    console.log(this.$route.params.id + " id");
    this.getPlayList();
  },
  methods: {
    getPlayList() {
      axios
        .get("/api/songlist", {
          params: {
            id: this.$route.params.id,
          },
        })
        .then((res) => {
          console.log(res.data);
          this.playlistData = res.data.data.songlist;
          this.img = res.data.data.logo;
        })
        .catch((err) => {
          console.error(err);
        });
    },

    goBack() {
      window.history.length > 1 ? this.$router.go(-1) : this.$router.push("/");
    },
    selectSong(item) {
      axios
        .get("/jsososo/song/urls", { params: { id: item.songmid } })
        .then((res) => {
          console.log(res.data.data[item.songmid]);
          this.songUrl = res.data.data[item.songmid];
        })
        .catch((err) => {
          console.error(err);
        });
    },
  },
};
</script>

<style scoped>
/* .title-img img {
  width: 100%;
  height: 300px;
} */
.title-img {
  position: relative;
}
.van-icon {
  color: rgba(243, 246, 30, 0.452);
  font-size: 30px;
  position: absolute;
  top: 5px;
  left: 0px;
}
.van-image {
  width: 50%;
}
.content-icon {
  position: relative;
  overflow: hidden;
  background-color: beige;
}
.box-left {
  float: left;
  height: 40px;
}
.box-left > span {
  display: inline-block;
  line-height: 40px;
}
.box-right {
  float: right;
}

.icon {
  position: relative;
  color: blue;
  font-size: 40px;
}

.content {
  width: 100%;
  text-align: left;
  border-radius: 20px;
}
.content > .item {
  background-color: azure;
  margin-top: 10px;
}
.content > .item > .songname {
  margin-top: 5px;
  font-size: larger;
  font-weight: bold;
}
.content > .item > .singInfo {
  margin: 5px;
}
</style>